package com.zhijian.medical.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.format.FastDateFormat;
import com.zhijian.medical.annotation.Response;
import com.zhijian.medical.config.CommonConfig;
import com.zhijian.medical.entity.vo.request.PersonTrainTestSaveOrUpdateVo;
import com.zhijian.medical.entity.vo.response.CodeVo;
import com.zhijian.medical.entity.vo.response.PersonTrainTestVo;
import com.zhijian.medical.service.PersonTrainTestService;
import com.zhijian.medical.service.impl.PersonTrainTestServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;

/**
 * 分子病理室人员岗前培训与考核表 控制层
 *
 * @author HCG
 * @version 1.0
 * @date 2023-07-18 14:21:25
 */
@Slf4j
@Controller
@Api(tags = "分子病理室人员岗前培训与考核表")
public class PersonTrainTestController {

    @Autowired
    private PersonTrainTestService service;

    @Autowired
    private CommonConfig commonConfig;

    /**
     * 获取最新编号们
     *
     * @return
     */
    @Response
    @GetMapping("/person/train/test/code")
    @ApiOperation("获取最新编号们")
    public CodeVo getNewCode() {
        CodeVo codeVo = new CodeVo();
        codeVo.setCode2(service.createNextCode());
        codeVo.setCode(PersonTrainTestServiceImpl.CODE_PREFIX);
        codeVo.setDw(commonConfig.getDw());
        codeVo.setVersion(commonConfig.getVersion());
        codeVo.setSaveTime(commonConfig.getSaveTime());
        codeVo.setZrr(commonConfig.getZrr());
        codeVo.setPublishDate(DateUtil.format(new Date(), FastDateFormat.getInstance("yyyy年MM月dd日")));
        codeVo.setExecuteDate(codeVo.getPublishDate());
        return codeVo;
    }

    /**
     * 新增或者修改
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/person/train/test")
    @ApiOperation("新增或者修改")
    public boolean saveOrUpdate(@RequestBody PersonTrainTestSaveOrUpdateVo param) {
        return service.saveOrUpdate(param);
    }

    /**
     * 根据人员ID查询
     *
     * @param personId
     * @return
     */
    @Response
    @GetMapping("/person/train/test/{personId}")
    @ApiOperation("根据人员ID查询")
    public PersonTrainTestVo selectByDeviceId(@PathVariable("personId") Long personId) {
        return service.selectVoByPersonId(personId);
    }

}